package com.cmg.services.qrcode.service;

import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import org.springframework.stereotype.Service;

import java.io.OutputStream;

@Service
public class QrCodeService {

    public void createQrCode2Stream(String content, int width, int height, OutputStream os) {
        QrCodeUtil.generate(content, initQrConfig(width, height), "png", os);
    }

    private static QrConfig initQrConfig(int width, int height) {
        QrConfig config = new QrConfig(width, height);
        // 设置边距，既二维码和背景之间的边距
        // config.setMargin(3);
        return config;
    }
}
